<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;
class DelController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    //AJAX请求 返回$_POST
    public function del($id)
    {
        DB::table('admin')->where('id',$id)->delete();
        return redirect('admin/user');
    } 
    public function cat_del($id)
    {
       
       self::del1($id);
       echo 11;

    }

    //递归删除
    public static function del1($id)
    {
        

        $count = DB::table('cats')->where('pid',$id)->count();
        if($count>0){
            $arr = DB::table('cats')->where('pid',$id)->get();
                foreach($arr as $val){
                     self::del1($val->id);
                  
                }

        }
        DB::table('cats')->where('id',$id)->delete();


       
    }
   
}